Jump to content

Help needed using getElementById()


Recommended Posts

I initially posted a question over in Data Pages and got what looks like a answer which should work.  However I am having trouble getting the suggested Java Script to work.  From that other Thread...

I was looking at this more and wondering if I needed to change the "Value1_1" and "Value2_1" strings to be specific to the Name or ID of the Controls on my Search Page, but I did not see anything which looked like what this might be.  Then I found this in the "JavaScript TipsCaspio Form Elements" help article... 

Search Forms

  • Text Field/Text Area/Dropdown/Checkbox/Listbox/Hidden:

          -   ValueX_Y
          -   X is the form element order, which starts at 1 and increments based on the order of the element in the form.
          -   Y is the criteria. It starts at 1 and increments based on criteria order. It is always 1 if the field has no extra criteria.

... which suggests to me I should not call my Search Fields "Controls"... I should call them "Elements".  :) Further they are not referenced by specific name, but rather by their position in the Form.  So if I have two Search Fields (both which are Text Fields... "Registration" and "Name"... in that order) a call to:

  document.getElementById("Value1_1").value;

...should theoretically get me the data entered for "Registration".  (A separate question is how to tell what the available "criteria" are for an Element, but I am working on the assumption that critera 1 in this case is the data entered by the User).  I have yet to get this to work though.  As far as I can tell the moment I add the "document.getElementById(..." call to the code it appears to short-circuit.

If I have the following...

 function check()
 {
   window.alert("1");
   window.alert("2");
 }
 document.getElementById("searchID").onclick=check;
 
... then when I click "Search" I get a pop-up box with "1", then another with "2", and it goes to the Results Page.
 

If I have this instead...

 function check()
 {
   window.alert("1");
   window.alert(document.getElementById('Value1_1').value);
   window.alert("2");
   window.alert(document.getElementById('Value2_1').value);
 }
 document.getElementById("searchID").onclick=check;
 
... then I get a pop-box with "1" and then it goes directly to to the Results Page.   It hits the "document..." code and goes *POOF*
 
Guessing this is bone-head simple and I am just a little to ignorant of things to understand what I am doing wrong.  Help!  :)
 
Russ
Link to comment
Share on other sites

Well.... As I suspected I was being a dolt.  I had an HTML box above the Search Fields giving instructions.  It was Value1 and "getElementById()" was not working against it and returning Null.  Executing the ".value" method against a Null object was causing the Script to short circuit.  Instead of using "Value1_1" and "Value2_1" I changed it to "Value2_1" and "Value3_1" and all was well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...