Web Hosting Talk







View Full Version : Javascript and textbox problem


monkey junkie
10-31-2004, 12:33 PM
Hello,

I have some simple Javascript which displays some default text in a textbox. When the user clicks the textbox the text disappears.

You can see this here -

http://www.staff.ie/new/

My problem is this -

If the user does NOT click in the textbox, but clicks the button "Search For Jobs", the default values in the textbox are being used as keywords.

Would any of you know a way I can change this so when the user clicks "Search For Jobs" and the default values are still in the textbox, the default values are ignored?

Thanks in advance :)

Steve

jasong
10-31-2004, 01:20 PM
Well, in your php code on the action page, you could just do...

<?php

if ( $search=="Keywords (Optional)" ){
$search="";
}

?>


That way it just resets the value of it if its the same as the default.

Hope that helps :)

-Jason

azizny
10-31-2004, 02:32 PM
I would add this (to prevent user form submitting in the first place):




<script>
function checktest(){
if(document.ddd.textboxname.value == 'Keywords (Optional)'){
return false;
}
return true;
//You could also put an annoying message to enter a word (which I would not prefer)
}
</script>
<form name="ddd" id="ddd" style="display:none;" onsubmit="return checktest();">

/////THE FORM

</form>

monkey junkie
11-01-2004, 07:54 AM
Thank you for your suggestions.

azizny - I would like to take your route, but unfortunately your code makes my keyword box disappear altogether. Are you sure it is correct?

Thanks again :)

xgoth3
11-01-2004, 01:17 PM
Just change your form tag to this:

<form method="GET" action="jobseekers_search.php" name="staffie" onSubmit="javascript:if(document.staffie.kw.value=='Keywords (Optional)'){ return false;}">

monkey junkie
11-02-2004, 02:53 PM
Thanks. I added the following and it now works as I wanted -

<form method="GET" action="jobseekers_search.php" name="staffie" onSubmit="javascript:if(document.staffie.kw.value=='Keywords (Optional)')

{document.staffie.kw.value='';}">

Thanks again :)