A page has a playscript in a php included file: (the playscript has hundreds of lines)
With php I’ve manipulated the playscript to contain certain tags
<lineNo1>, <charName1> and <dialogue1>
Using <?php echo $i;$i++;?>, I’ve incremented the whole script so it has 25 Lessons, each with 10 lines of dialogue, and each line of dialogue displays those parameters correctly, i.e.:
<div id="dialogue">
<div id="1">
<Lesson1>Lesson 1</Lesson1>
<lineNo1>1</lineNo1>) <charName1>Sherry</charName1>
<dialogue1>Look at this, I'm shaking.</dialogue1></div></div>
All that php works great through 250 iterations, but my jquery skills are nascent and my script is bogus.
On click of <Insert>Insert</Insert>, I need to transfer the text values, i.e. ‘1’, ‘Sherry’ and ‘Look…shaking.’ from inside the tags to form text input fields,
LIne, Speaker and LIneX:
<div id="LessonNumber1">
<div id="LineNumber1">
<input type="text" name="Line" id="Line" value="" />
<input type="text" name="Speaker" id="Speaker" value="" />
<input type="text" name="LineX" id="LineX" value="" />
</div></div>
My jquery script, below, works partially. The first input text field, ‘Line’ is receiving the (<?php echo $LineItem;?>).text; value perfectly, for obvious reasons.
But the other fields are receiving [object Object]; all my research on [object Object] has led me in circles, ultimately here.
Will someone please tell me how to re-write the last two lines, for #Speaker and #LineX so that the actual values will appear in the form fields instead of [object Object]?
<script type="text/javascript">
$(document).ready(function(){
$("Insert").click(function(){
$("#TheForm #LessonNumber<?php echo $LineItem;?> #LineNumber<?php echo $LineItem;#Line").val(<?php echo $LineItem;?>).text();
These last two are examples of my problem.
$("#TheForm #LessonNumber1 #LineNumber1 #Speaker").val("what goes here if not <charName1></charName1>").val();
$("#TheForm #LessonNumber1 #LineNumber1 #LineX").val("what goes here if not <dialogue1></dialogue1>").text();});});</script>
Many thanks.
val and text are functions, you must add () to call them and get their results. If you
juste write val or text, it’s the reference to the function itself (and in js, a function is an object).
this will set the value of input field ‘myfield’ with the text inside the element ‘mytext’
Try to do the same in your code