Jump to content


Photo

Focus of text field changes when field is full?


  • Please log in to reply
6 replies to this topic

#1 Roble

Roble
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 August 2006 - 04:17 AM

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.

#2 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 17 August 2006 - 04:23 AM

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

#3 Jeremysr

Jeremysr
  • Members
  • PipPipPip
  • Advanced Member
  • 199 posts
  • LocationSaskatchewan, Canada

Posted 17 August 2006 - 04:29 AM

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.

#4 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 17 August 2006 - 04:30 AM

well this time i found it for u create a function on top of page and it would be like

<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()}
}
?>

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

#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 04:34 AM

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.

#6 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 17 August 2006 - 04:37 AM

Um... BillyBoB's code should be in...

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

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


#7 Roble

Roble
  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 August 2006 - 11:54 PM

Billy your script worked marvelousely (I put it within JS tags like thorpe says to do)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users