1

I want to get information from a previous form that was entered in a textBox. I am currently trying something like this:

var accNumber = $('#index.html').RegisterForm.cardNumberRegField.val();

and I have also tried

var tfscNum = document.RegisterForm.cardNumberRegField.value;

I know this is wrong. The HTML page I want to get the information from is index.html, and the form id is RegisterForm. The ID of the textBox in that form is cardNumberRegField

EDIT

this is the html code i am using for the textBox and the button on the index.html page

<form id="RegisterForm" method="post" data-ajax="false" id="registerCardForm" action="register.html"> 
        <input type="text" id="cardNumberRegField" type="tel"  name="cardNumber" class="required number register" minlength="16" maxlength="16"/> 
        <input name="Submit" type="submit" class="button" value="Register"/>
    </form>

Does anybody know the correct way to do this?

Hip Hip Array
  • 4,665
  • 11
  • 49
  • 80

1 Answers1

0

If the textbox is on the same page and you have the ID attribute set then simply $('#cardNumberRegField').val(); will return the value.

gunnx
  • 1,229
  • 7
  • 16
  • no the textBox is not on the same page, it is on the previous page – Hip Hip Array May 09 '12 at 16:08
  • Are you submitting the form on the previous page? If so then the values would be available via $_POST or $_GET depending on the method you use. – gunnx May 09 '12 at 16:25
  • what do you mean by 'submitting' the form? – Hip Hip Array May 09 '12 at 16:29
  • so when you press the submit button it goes to nextpage.php and in this case $_POST array will be filled with all the form fields you have. – gunnx May 09 '12 at 16:34
  • oh right, ya i am submitting the form from the previous page, and using a mehtod="post" – Hip Hip Array May 10 '12 at 08:03
  • Ok so you should be able to access via $_POST["cardNumberRegField"]. Do you use 'name' attribute for your form fields or just the 'id'? – gunnx May 10 '12 at 08:10
  • i have added the code to my question of how the textBox and button are added, as you can see i use for the textBox i just use 'id' but for the button i use 'name' – Hip Hip Array May 10 '12 at 08:14
  • ya i was trying it there and it wasnt working at all... i take it your suppose to put 'echo $_POST['cardNumber'];' in the .js page and not the .html page ya? ...... because it was trying to use it like var details = { .... tfscNumber : echo $_POST['cardNumber'], ...} to add it to an array – Hip Hip Array May 10 '12 at 09:24
  • I just noticed you don't mention which language you are using to deal with the POST, the form action goes to register.html but are you using PHP? – gunnx May 10 '12 at 09:44
  • you will need some sort of server side language to access the POST/GET data. – gunnx May 10 '12 at 10:25