Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return to field in form from alert box

Status
Not open for further replies.

plaberge

Programmer
Apr 4, 2002
4
0
0
US
I am using alert to return to a form if it is not filled out correctly. For example, I have a field for quantity that must be from 1 to 99. My code is:

temp = document.item0.QTY.value;
if (temp > 0 && temp < 100) {
...
} else {
alert (&quot;Select a numeric Quantity greater than 0 and less than 100&quot;);
document.item0.QTY.focus();
document.item0.QTY.select();
return false;

But when I click OK on the popup window, it goes back to the top of my web page instead of to this field in the form. What am I doing wrong? Do I have something missing on the form?

Thanks!
 
Post your code, we can't guess what your code contains.

Have Fun...

Sharky99 >:):O>
 
Here is my form code:

<form name=&quot;item0&quot;> <b>Qty:</b> <input id=&quot;f00&quot; name=&quot;QTY&quot; type=&quot;text&quot; value=&quot;1&quot; size=&quot;2&quot;>

<select id=&quot;f01&quot; name=&quot;Color&quot;>
<option value=&quot;selected&quot;>Select Color</option>
<option>Sports Grey </option>
<option>Bimini </option>
<option>Bright Royal </option>
<option>Pine </option>
</select>

<select id=&quot;f02&quot; name=&quot;Size&quot;>
<option value=&quot;selected&quot;>Select Size</option>
<option>S</option>
<option>M</option>
<option>L</option>
<option>XL</option>
<option>2XL (add $2)</option>
</select>
</form>
 
Sorry but it would be better to post the WHOLE code from that page.

I know you return false but to which function call?????

Or try to put the alert after the:

document.item0.QTY.select();



Have Fun...

Sharky99 >:):O>
 
hi

>.. id=&quot;f00&quot; name=&quot;QTY&quot; why do you use differnt id & name? may be that's your prob?

try the same code (the code is workable) but remove/rename your id's names/ids

try also document.forms instead of document
 
I got it figured out. It is probably pretty basic but I am very new to javascript.

Here was my old call:
<a onclick=&quot;MakeBuy (0)&quot; href=&quot;#&quot;>
<img src=&quot; border=&quot;0&quot; width=&quot;106&quot; height=&quot;24&quot;></a>

Here is my fixed call:
<a onclick=&quot;MakeBuy (0);return false&quot; href=&quot;#&quot;>
<img src=&quot; border=&quot;0&quot; width=&quot;106&quot; height=&quot;24&quot;></a>

The &quot;return false&quot; does the trick

Thanks for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top