Set input value in new loaded form

I have this link that creates several divs in which the form is loaded via load (). This form is in a separate php file. Now I want to use the ID value of my link to set the value of the input field, but how?

I know that I need live () for this, but setting the value should be automatic, not after the event.

This is the situation as below

main.php


[..]
<a href="form.php" rel="box" id="inputvalue">

form.php


<form>
[..]
<input type="text" id="el">

Now I want to set 'inputValue' (when loading form.php) as the new value of $ ("# el"), but how?

My javascript file is in main.php and the way to load form.php is as follows


$("a").click(function(){
 if(this.rel == "box"){
  [..]
  $("#container").load("form.php");

When the form is displayed, I want to change the input value

+3
source share
3

, . load().

var linkId = this.id;
$("#container").load("form.php", function() {
    $(this).find('#el').val(linkId);
});

, id . .

+4

, :

$("a").click(function(){
 if(this.rel == "box"){
  var clicked = this;
  $("#container").load("form.php", function() {
     $("#el").val( $(clicked).attr("id") );
  });
0

You can use the plugin liveQueryavailable here: http://brandonaaron.net/code/livequery/docs . This is a bit like live(), but instead of binding an event, it executes code for each matched element.

0
source

Source: https://habr.com/ru/post/1765426/


All Articles