Results 1 to 5 of 5

Thread: jquery copy input to other input

  1. #1
    Join Date
    Dec 2008
    Posts
    48
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default jquery copy input to other input

    Hello, i am trying to create a URL friendly address based on an input given by a user. This is with jquery.

    Code:
    	<script type="text/javascript">
    	function suggestUrl() {
    
    		var title = ('twig_title');
    		title = title.replace(/\,/g, '-');
    		title = title.replace(/ /g, '-');
    		title = title.replace(/\@/g, '_at_');
    		title = title.replace(/[^A-Za-z0-9_\-]/g, '');
    		title = title.replace(/-+/g, '-');
    		title = title.replace(/-+$/g, '');
    		$('twig_name').value = title;
    
    		return true;
    	}
    	</script>
    
    
    <form id="step1" name="step1" action="" method="post">
    
    <input name="twig_title" type="text" id="twig_title" " onChange="showtwigtitle(this.value)">
    
    <input type="text" name="twig_name" id="twig_name"  onChange="showtwigname(this.value)">
    </form>
    I took this code from another site and cant seem to find what i am missing. Thanks for the help.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,127
    Thanks
    44
    Thanked 3,228 Times in 3,189 Posts
    Blog Entries
    12

    Default

    Your HTML markup has a syntax error:

    Code:
    <input name="twig_title" type="text" id="twig_title" " onChange="showtwigtitle(this.value)">
    But that probably isn't the problem, definitely not the main problem. It should be fixed though. Simply remove it.

    The main problem I see is that there are no:

    Code:
    showtwigtitle()
    or:

    Code:
    showtwigname()
    functions defined. It looks like these should both perhaps be:

    Code:
    suggestUrl()
    I'll try that out and get back to you.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,127
    Thanks
    44
    Thanked 3,228 Times in 3,189 Posts
    Blog Entries
    12

    Default

    OK, this sort of works:

    Code:
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
    	<script type="text/javascript">
    	function suggestUrl(val) {alert(val);
    
    		var title = val;
    		title = title.replace(/\,/g, '-');
    		title = title.replace(/ /g, '-');
    		title = title.replace(/\@/g, '_at_');
    		title = title.replace(/[^A-Za-z0-9_\-]/g, '');
    		title = title.replace(/-+/g, '-');
    		title = title.replace(/-+$/g, '');
    		$('#twig_name').val(title);
    
    		return true;
    	}
    	</script>
    
    
    <form id="step1" name="step1" action="" method="post">
    
    <input name="twig_title" type="text" id="twig_title" onChange="suggestUrl(this.value)">
    
    <input type="text" name="twig_name" id="twig_name"  onChange="suggestUrl(this.value)">
    </form>
    But I question the wisdom of the particular regExp's used with the replace commands, and am at a loss as to what the intended output is. If it is the intention to produce a syntactically valid URL, those regExp's need to be changed.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Dec 2008
    Posts
    48
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default

    hi and thanks for the help. I am sorry i missed up my example, the functions showtwigtitle(this.value) and showtwigname(this.value) call something else (a title and name availability script). Also the extra " found there is because i deleted some code for posting here and clearly failed to do it well.

    I need the field twig_title to be copied to the field twig_name while being regexed. I will then have a twig name and a friendly seo url to call it with php.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,127
    Thanks
    44
    Thanked 3,228 Times in 3,189 Posts
    Blog Entries
    12

    Default

    OK, so did this answer question?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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