0

I have some code.

$('#my-mkfile').click(function(e) {
    e.stopPropagation();
    e.preventDefault();
    //window.console.log('mkdir button pressed');
    f[0].elfinder.ui.exec('mkfile');
    $('#finder .el-finder-cwd').find(':text').val('XXXXXX');
    $(document.body).click();
    var timestamp=0;
}

At the moment it works with a button. And creates a val named 'XXXXXX'

<input type="button" value="my mkfile" id="my-mkfile">

How can I change it so that it is a text field and passes to val('XXXXXX'). I just spent a day on it lol. Should be easy.

7
  • I don't understand what you mean. Commented Dec 20, 2010 at 0:53
  • Sorry if its not clear. I will try to explain. I need a textfield in a form that can take the user input and pass it as a variable. I am not sure if I can do this without ajax. Commented Dec 20, 2010 at 1:09
  • Whereto do you want to pass it? Maybe you want to create a new <input type="text" id="someId" value="" /> then set its value to 'XXXX' $("#someId").val('XXXX'); then you can always fetch that value by .val(); on the input text field element. Commented Dec 20, 2010 at 1:11
  • Thanks for reply Antonio. The value is set to XXXXX for my example, and this is the value that is being sent. SO when I press a button it creates a file on elfinder file manager called XXXXX. How could I make it so it takes the user input instead of using XXXXX. many thanks. Commented Dec 20, 2010 at 1:22
  • @Simon... All you have to do is remove the line that sets the value: $('#finder .el-finder-cwd').find(':text').val('XXXXXX'); Commented Dec 20, 2010 at 1:26

1 Answer 1

1

Add a text field

<input type="text" id="textFieldID" value="" /> 

and change the code to

$('#finder .el-finder-cwd').find(':text').val($('#textFieldID').val());
Sign up to request clarification or add additional context in comments.

5 Comments

BRILLANT.THANKS. I spent all day on this. Much appreciated amit. I owe you.
@Simon why don't you flag this as an answer?
Sorry just one further thing. I wish to pass the same variable to an ajax function. $.get("ajax.php",{'action':'new','text':'XXXXXXXX.','rand':Math.random()},function(msg){ XXXXXX is where I need to pass the val($('#textFieldID' variable. Also Is there a tool for checking javascript syntax. I am quite new but my main problem is syntax errors.
@Simon, $.get("ajax.php",{'action':'new','text':$('#finder .el-finder-cwd').find(':text').val($('#textFieldID').val()),'rand':Math.random()},function(msg){ ... You should look into using an IDE, or a very good editor such as vim. If your serverside is Java then lookinto Eclipse or Netbeans. If its python try pycharm, if its php try vim, or somethiing like Notepad++. If you want more, Intellij I think has even better inspections.
Sorry, should have been, $('#textFieldID').val() this will give you the value of the textField input element and you can place it anywhere you like where you need that value, even computations or ajax.

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.