开发者

How does onchange carry selected text and hidden value?

开发者 https://www.devze.com 2023-03-18 03:48 出处:网络
I have a dynamically populated PHP dropdown menu that gathers the following information from the database:

I have a dynamically populated PHP dropdown menu that gathers the following information from the database:

echo '<option value=&q开发者_开发技巧uot;'.$image['id'].'">'.$image['description'].'</option>';

I then have a JavaScript function that shows the selected text - description in an input box for editing and then on submit update back into the database.

Question: Is there away using JavaScript that I could pass the id and description together but only have the description show in the input box for editing?

$('#captionSelect').change(function(){
        $('#captionInput').val($("#captionSelect option:selected").text()).show();
    });


you can try this.

$('#captionSelect').change(function(){
        $('#captionInput').val($("#captionSelect option:selected").html()).show();
    });

Thanks.


hello jess Try this out....

 $('#captionSelect').change(function(){
            $('#captionInput').val($("#captionSelect").val());
    });


You would need to add a hidden form field to your form.

Then you can use:

$('#captionSelect').change(function(){
    var $selected = $("#captionSelect option:selected");
    $('#hiddenField').val($selected.val());
    $('#captionInput').val($selected.text()).show();
});

I added the $selected to avoid multiple look-ups.

0

精彩评论

暂无评论...
验证码 换一张
取 消