Cross reference URL submit to form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Stuart Hunter
    New Member
    • Jan 2011
    • 13

    Cross reference URL submit to form

    After browsing and crudely dusting off my JS knowledge over the past few day's I'm stumped on how to do this effectively as a lot of the parameters I've read are very outdated?

    Simply I want to determine the value of the current page URL and if accurate it will then return a value that will be assigned to a form text box.

    e.g. If the URLs are as such for example:





    Then if the user visits test.com/number2 the form will automatically populate itself with 'This is page Number 2'.

    My code seems to return the string regardless of the URL, but also creates a seperate form, it does not post to the form which has the correctly assigned ID and NAME.

    If any one can help or point me in the right direction it would be really really help thank you.


    Code:
    var prod_name = parent.location.href
    {
    if (prod_name = "http://www.test.com/number2")
    	{document.write("<input type='text' name='Test_Name' id='Test_Name' value='This is page number 2'>");
      	}
    }



    UPDATE: I have revised the code to look something more like below, but it is still returning the web value if any of the characters are present i.e. it will return 'true' if even 'www.' was present.

    Is there a specific way determine the entire string of the URL for the reference?

    Code:
    var NAME = parent.location.href
    
    if (NAME = "http://www.test.com/page1")
          {
    	   
          var name_element = document.forms["formname"].elements["pagename"];
          //alert("name_element = " + name_element);
          
          name_element.value = "THIS IS PAGE ONE";
          if (pagename.length >= 5)
             {        
             name_element.readOnly=true
             }
        
    	 else
    	 
    	 name_element.value = "Enter PAGE";
          if (prod_name.length >= 10)
             {         
             name_element.readOnly=false
    		 }
    	  }
    Last edited by Niheel; Jan 18 '11, 10:28 AM. Reason: updated code
Working...