2 Replies - 545 Views - Last Post: 27 August 2012 - 05:07 PM

#1 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

How to get textbox entry?

Posted 24 August 2012 - 06:25 PM

Why can't I get the textbox entry?

<form id="bet-form">
<table>
....
<tr><td colspan=5>multiply: <input type="text" id="multiple" size="2" value="1" onkeypress="multiply()"></td></tr>
</table>
</form>


function multiply()
{
    multiple=document.forms['bet-form'].elements[39].value;     
    alert(multiple);  
}


elements[38] is what I expected, the very next <input> is the text box but the alert shows nothing?

Is This A Good Question/Topic? 0
  • +

Replies To: How to get textbox entry?

#2 Sho Ke  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 110
  • View blog
  • Posts: 250
  • Joined: 13-October 11

Re: How to get textbox entry?

Posted 24 August 2012 - 06:42 PM

You're just wanting the value of <input type="text" id="multiple" size="2" value="1" onkeypress="multiply()">, correct? If that's the case, change

document.forms['bet-form'].elements[39].value;

to

document.getElementById("multiple").value;

Edit: working example here.
Also, it looks like you might be using tables for styling/positioning. It's generally not a good idea to use tables for non-tabular data. Lemur did a good job discussing this here. Most notably, making changes to a Web site's design that uses tables for styling is very time consuming and often a headache to accomplish, but using proper CSS, site-wide changes can be made with a single file save.

This post has been edited by Sho Ke: 24 August 2012 - 06:55 PM

Was This Post Helpful? 2
  • +
  • -

#3 g37752  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 195
  • Joined: 24-July 12

Re: How to get textbox entry?

Posted 27 August 2012 - 05:07 PM

thanks.
i had to change onkeypress to onkeyup for it to work correctly. otherwise it get my last entry. i wonder why? and I wonder why document.forms['bet-form'].elements[39].value; doesnt work?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1