HTML/Javascript question

Discussion in 'Software' started by unclematty, Feb 2, 2004.

  1. unclematty

    unclematty Private First Class

    I have an input element named txtWord

    I am trying to reference its value onclick of another element.

    I tried document.txtWord.value, but it didnt work.
    I also tried document.forms.form1.txtWord.value, no avail.

    form1 is the name of the form.

    What is the correct way to reference it?

    Thanks.
     
  2. Kodo

    Kodo SNATCHSQUATCH

    document.formname.formelementname.value

    so

    document.form1.txtWord.value

    it's case sensitive too.
     
  3. unclematty

    unclematty Private First Class

    Kodo, you are the man!! Always lending me ahelping hand. i really appreciate it!
     
  4. unclematty

    unclematty Private First Class

    couldnt i have found that out with an alert?

    for instance, could i have done somehting like this to get the correct path...
    alert(this.{something});
     
  5. Kodo

    Kodo SNATCHSQUATCH

    I'm not sure. My javascript knowlege is awful. I only know that little bit because of other previous experience in using scripts that reference form elements.
     
  6. goldfish

    goldfish Lt. Sushi.DC

    coulda just used document.all.txtWord.value to start with, its a bit cheating though
     
  7. Kodo

    Kodo SNATCHSQUATCH

    isn't that slower?
     
  8. unclematty

    unclematty Private First Class

    this isnet working. do you see what the problem is?

    <form id="frm" method="post" runat="server">
    &nbsp;<INPUT type="amount" value=1" onclick="this.value='';">
    <INPUT type="button" value="Lookup" onclick="alert(document.all.amount.value);">
    </form>
     
  9. Kodo

    Kodo SNATCHSQUATCH

    dude.. I posted an answer for that at like 3pm today.. I have no idea why it didn't post.
    Anyway. Take a look at what your input type is for the amount.. ;) you set your input type to "AMOUNT" when it should be "TEXT". The NAME should be "AMOUNT" ;)

    ;<INPUT type="text" name="amount" value=1" onclick="this.value='';">
     
  10. unclematty

    unclematty Private First Class

    Thanks again. Kodo to save the day! It is always something simple.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds