Welcome Guest, Not a member yet? Register   Sign In
jquery issue
#1

[eluser]kyleect[/eluser]
I don't know if it's cool to post jquery questions here and if it's not I'll delete the post but... I'm trying to build a tags module where a user enters a tag and when the form is submitted it is added to the disabled input with the previous tags with comma space separation. My javascript is iffy at best so could someone tell me what I'm missing? Thanks!

main.js:
Code:
$(document).ready(function(){
    $('#tags_form').submit(function(){
        var tag;
        var tags_array;

        tag = $('#tag').value();
        tags_array = $('#tags').text();
        tags_array = tag.split(', ');
                
        for(var i in tags_array){
            tags_array.push(i);
        }
        
        tags_array = tags_array.join(', ');
        
        tags_array = $('tags').text(tags_array);
        

    });
});

home.php:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;&lt;?=$this->config->item('name', 'app')?&gt; - Home&lt;/title&gt;
        [removed][removed]
        [removed][removed]
    &lt;/head&gt;
    
    &lt;body id=""&gt;
        <h1>&lt;?=$this->config->item('name', 'app')?&gt;</h1>
        
        <div>
            &lt;form action="home" method="post" id="tags_form"&gt;
                <p id="tags_input">&lt;input type="text" name="tag" value="" id="tag"&gt; &lt;input type="submit" id="submit" name="submit" value="+ Tag"&gt;&lt;/p>
                <p>&lt;input type="text" name="tags" value="" id="tags" disabled="disabled"&gt;&lt;/p>
            &lt;/form&gt;
        </div>
        
    &lt;/body&gt;
&lt;html&gt;
#2

[eluser]Krzemo[/eluser]
Im not sure if this is what you mean to have but think of something like that (taken from top of my head without testing):
Code:
$("input#submit").click(function() {
    var tags = $("input#tags").val() + ", " + $("input#tag").val();
    $("input#tags").attr("value", tags);
});




Theme © iAndrew 2016 - Forum software by © MyBB