2

I am using jQuery for the first time. I've been searching a lot but have not gotten the answer.

I want to insert an input Type at id="star" and with value="score Star" but I'm not able to do that. Score returns the numeric value. I think the problem is in the value attribute, but I don't know where. Thanks In Advance.

Here's the code:

<script type="text/javascript">
            $(function() {
                $('#click').raty({
                    click: function(score) {
                        document.getElementById('star').innerHTML="<input type='text' name='type' value='"score+ "' Star >";
                        //alert( 'score: ' + score);

                        }
                    });
                });
</script>



          <label>Deal Type:</label>
         <div id="click"></div><span  id="star"></span></div>
1
  • value='"score+ "' <--- you miss a '+' Commented Dec 13, 2012 at 18:14

4 Answers 4

2

You're not writing the code correctly

.innerHTML="<input type='text' name='type' value='"score+ "' Star >";

It should be

.innerHTML="<input type='text' name='type' value='"+score+" Star' >";
Sign up to request clarification or add additional context in comments.

Comments

2

You're not concatenating the string, or quoting the value correctly

.innerHTML="<input type='text' name='type' value='"score+ "' Star >";

should be

.innerHTML="<input type='text' name='type' value='" + score + " Star' >";

1 Comment

@Asad - yeah, I got that in there while you were writing the comment
1
<script type="text/javascript">
            $(function() {
                $('#click').raty({
                    click: function(score) {
                        document.getElementById('star').innerHTML="<input type='text' name='type' value='"+score+ " Star'>";
                        //alert( 'score: ' + score);

                        }
                    });
                });
</script>



          <label>Deal Type:</label>
         <div id="click"></div><span  id="star"></span></div>

Comments

0

A better approach is to actually create an input DOM object and append it:

$('#star').append($('<input/>').attr({
    type: "text",
    name: "type",
    value: score + " Star"
}));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.