Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation Combine User input and URL to load page

    I'm working in iWeb (I had to say that first). I need to create (using JAVASCRIPT) a text box with a button. When the button is clicked, the contents of the box are added to the URL (the url is in the code, probably a variable, for this example it is mydomain.wordpress.com/) and the url produced loads. For example, if the text "Hello" was printed in the text box once the button is clicked the page mydomain.wordpress.com/Hello is loaded.

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    do you need the script to also create the button or does the button exist already for your example?

  • Users who have thanked DanInMa for this post:

    abn3566 (07-06-2011)

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    do you need the script to also create the button or does the button exist already for your example?
    I need the code to create the button.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    function to create element, change the green text to reflect the base url of the site.
    Code:
    <script>
    
    function add_my_button(id) {
      		input = document.createElement("input");
      		input.setAttribute("type", "button");
      		input.setAttribute("name", 'buttName_' + id);
      		input.setAttribute("id", 'buttID_' + id);
    		input.setAttribute("value", 'go here');
      		document.body.appendChild(input);
      		input2 = document.createElement("input");
      		input2.setAttribute("type", "text");
      		input2.setAttribute("name", 'textName_' + id);
      		input2.setAttribute("id", 'textID_' + id);
      		document.body.appendChild(input2);		
    		input.onclick = function() {
    		var base_href= "http://127.0.0.1/"
    		var user_val = document.getElementById('textID_' + id).value;
    		window.location=base_href+user_val
    	 }
    	 
    	 }
    </script>
    this is how you include it.

    Code:
    <script>add_my_button("1");</script>

  • #5
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks!

    I tried it using the code below (I just put the button after the text box and changed its value to "Log In") and it is not working.

    Code:
    <script>
    
    function add_my_button(id) {
    		input2 = document.createElement("input");
      		input2.setAttribute("type", "text");
      		input2.setAttribute("name", 'textName_' + id);
      		input2.setAttribute("id", 'textID_' + id);
      		document.body.appendChild(input2);
    		input = document.createElement("input");
      		input.setAttribute("type", "button");
      		input.setAttribute("name", 'buttName_' + id);
      		input.setAttribute("id", 'buttID_' + id);
    		input.setAttribute("value", 'Log In');
      		document.body.appendChild(input);		
    		input.onclick = function() {
    		var base_href= "my.curtaingalleries.com/"
    		var user_val = document.getElementById('textID_' + id).value;
    		window.location=base_href+user_val
    	 }
    	 
    	 }
    </script>
    
    <script>add_my_button("1");</script>
    my.curtaingalleries.com redirects to curtaingalleries.wordpress.com


    It is currently at login.curtaingalleries.com and the test username is "admintesting"
    Last edited by abn3566; 07-06-2011 at 03:29 AM. Reason: wrong url

  • #6
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    852
    Thanks
    173
    Thanked 94 Times in 94 Posts
    Hi

    Look at your base href. Wrong: var base_href= "curtaingalleries.wordpress.com/"

    example:

    Code:
    var base_href= "http://translate.google.com/"

    LT
    Last edited by low tech; 07-06-2011 at 04:06 AM.

  • #7
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    then you should be using:

    Code:
    var base_href= "http://my.curtaingalleries.com/"
    im still trying to figure out why the script has to create the button, seeing as how you have access to the html, but iot was fun to figure out.

  • #8
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    awesome now hes adding stuff that doesnt work directly to the html. I lvoe it when you spend your time on something and people dont even pay attention to the instructions.

  • #9
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for all of your help DanInMa and low tech. I am very close to having this entire problem solved. The button is now working except that it is opening the page in an iframe. How do I make the button open the new page in a new window and (obviously I'll just choose one method) in the same window?

  • #10
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    1. it didnt work the first time becuase you didnt put in the website address correctly.

    2. the current code you have on the login page does absolutely nothing so I have no idea how you are getting a frame of any kind.

  • #11
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    ok your adding the code in some kind of widget iframe, I wont ask why.

    correction this is it. have to do it his way since your adding the code to an iframe source file.

    Code:
    <script>
    
    function add_my_button(id) {
    		input2 = document.createElement("input");
      		input2.setAttribute("type", "text");
      		input2.setAttribute("name", 'textName_' + id);
      		input2.setAttribute("id", 'textID_' + id);
      		document.body.appendChild(input2);
    		input = document.createElement("input");
      		input.setAttribute("type", "button");
      		input.setAttribute("name", 'buttName_' + id);
      		input.setAttribute("id", 'buttID_' + id);
    		input.setAttribute("value", 'Log In');
      		document.body.appendChild(input);		
    		input.onclick = function() {
    		var base_href= "http://my.curtaingalleries.com/"
    		var user_val = document.getElementById('textID_' + id).value;
    		parent.document.location=base_href+user_val
    	 }
    	 
    	 }
    </script>
    Last edited by DanInMa; 07-06-2011 at 04:35 AM.

  • Users who have thanked DanInMa for this post:

    abn3566 (07-06-2011)

  • #12
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    or
    Code:
    parent.document.location=base_href+user_val

  • Users who have thanked DanInMa for this post:

    abn3566 (07-06-2011)

  • #13
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    5
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by DanInMa View Post
    or
    Code:
    parent.document.location=base_href+user_val
    That did the trick! Thanks again!

    I do have one more question though...how do I make the code work so that when I hit return, the button "is pressed"?

  • #14
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Quote Originally Posted by abn3566 View Post
    That did the trick! Thanks again!

    I do have one more question though...how do I make the code work so that when I hit return, the button "is pressed"?
    you should have asked that in the beginning and mentioning your using the code in a frame would have helped immensely.

    here use this.
    Code:
    <script>
    function redirect(dataform) {
    
    		var base_href= "http://my.curtaingalleries.com/"
    		var user_val = dataform.txt1.value;
    		parent.document.location=base_href+user_val
    		return false
    		}
    </script>
    <form action=""  name="myForm" id="myForm" onsubmit="return redirect(this)">
    <input name="txt1" id="txt1" type="text" />
    <input name="" type="submit" value="Login" /></form>
    Last edited by DanInMa; 07-06-2011 at 05:27 AM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •