Jump to content

Archived

This topic is now archived and is closed to further replies.

Roble

Focus of text field changes when field is full?

Recommended Posts

Hello,

I'm working on my dad's insurance website, and I was making the quotes form. He's told me that he wants the licence number to be entered into 3 text fields, each having a maxlength of 5. But he wants the fields so that when the first text field is filled out, it will go on to the second, and then on to the third after that. He wants it to be automatic, so his potential clients dont have to hit tab. I've tried doing this with JS, but to no avail. Wondering if this can be done using PHP? If not can you give me a better JS script then the one I found? Much appreciated.

Share this post


Link to post
Share on other sites
u could create a script so when text is entered then check if 5 numbers or watever has been entered then focusing on the next box right ? i dont exactly know but u can google it im sure

Share this post


Link to post
Share on other sites
No I'm pretty sure this can't be done in PHP. I think you need to use Javascript, but I'm not sure how to do this.

Share this post


Link to post
Share on other sites
well this time i found it for u create a function on top of page and it would be like

[code]
<FORM NAME="cc">
<INPUT TYPE="text" name="num1" size="5" onKeyUp="check()"><BR>
<INPUT TYPE="text" name="num2" size="5" onKeyUp="check2()"><BR>
<INPUT TYPE="text" name="num3" size="5" onKeyUp="check3()"><BR>
<INPUT TYPE="submit" VALUE="Click to Send" NAME="go">
</FORM>


<?php
function check()
{
var letters = document.cc.num1.value.length +1;
if (letters <= 5)
{document.cc.num1.focus()}
else
{document.cc.num2.focus()}
}

function check2()
{
var letters = document.cc.num2.value.length +1;
if (letters <= 5)
{document.cc.num2.focus()}
else
{document.cc.num3.focus()}
}

function check3()
{
var letters = document.cc.num3.value.length +1;
if (letters <= 5)
{document.cc.num3.focus()}
else
{document.cc.go.focus()}
}
?>
[/code]

sorry jeremy i proved u wrong (i hate doing that)

Share this post


Link to post
Share on other sites
You really dont want to do this in php, Javascript is made for this. There is an entire forum on thsi board dedicated to client side issues... best you ask your question there.

Share this post


Link to post
Share on other sites
Um... BillyBoB's code should be in...

[code]
<script language="javascript">
// code here
</script>

tags, and included into your <head> seeing as its Javascript and NOT php.[/code]

Share this post


Link to post
Share on other sites
Billy your script worked marvelousely (I put it within JS tags like thorpe says to do)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.