I have a button in my php view by which I can add textboxes to my page inside a form. But Whe I am getting the value of that control in my php controller the value is not there.
Is there any way by which we can get the value of dynamically added textboxes inside a POST form.
if you know the number of textbox you have, add the textbox before with a css style display:none; and display it in js on click event - for exemple with jquery
$('.yourclass').show();
it will act like a classic form
if you don't know the number you can have
you can send the form by js and get the value by something like that:
var myArray = [];
$('.yourclass').each(function() {
//unidimentionnal array exemple
myArray.push($(this).attr('myAttribut'));
});
console.log(myArray);
Seb
Related
I have one functionality to get the print of current page. So to prepare the content, I am showing everything on one popup up first then later a print popup and then print command.
Trying to do the same with below code.
$('#button').on('click',function() {
var popup = window.open("","mypopup","width=500,height=300");
var html = $("#form").html();
$(popup.document.body).html(html);
popup.print();
});
JSFiddle
Tried with clone() method as well but not working.
So the issue is, I am not getting the element's values in my popup.
Thanks
HI Use simple jquery line for each input field.
You can add a value attribute for your input fields.
I have changed your script a bit. Please refer it.
$('#button').on('click',function() {
var popup = window.open("","mypopup","width=500,height=300");
// I am setting the value attribute in the html . Do this for all fields
// with similar input fields you can have a jQuery('input').each(); loop
$('#name').attr('value',$('#name').val());
var html = $("#form").html();
$(popup.document.body).html(html);
popup.print();
});
Manually send the data from form through ajax call and store it in a local websql (browser)storage which can be retrived in the print preview dialog box
I'm creating an array of input in my form. And i wanna get this array on my controller in Laravel.
My inputs is hidden type, and i add this fields dynamically through JavaScript, using Backbone.
I add this inputs on my form:
<input type="hidden" name="id_poi[]" class="id_poi" value="">
The value is also set dynamically in JavaScript.
After i add this input, this is my DOM:
So, i can add many inputs on my form.
When i'll handle this array on Laravel, i just get the value of the last input of this array.
I'm testing in this way:
public function store() {
var_dump(Input::all());
return;
}
And i had this output:
What i'm doing wrong to fail to get the values in an array?
EDIT:
I had other element with the same name in my form, and i change it.
But the problem isn't solved yet, when i submit the form, the elements added dynamically isn't sent to PHP. Resulting in the same output above.
inputs is hidden name edit. Example
name="id_poi[0]"
name="id_poi[1]"
Sory, my English not good.
I have a web page with drop down menus and many other stuff.
I want to retrieve the value of dropdown menu, I know it can be done using $_POST after submission. But I want to retrieve it before submissions and hence using javascript code.
document.getElementById().value;
I am confused on how to write this code in my form page.
echo $form->dropDownlist($model2,'ename',CHtml::listData
(Lists::model()->findAll(),'ename','ename'));
How can I call the function to javascript in the form page?
The Dropdown id Like YourModelname_ename
Get the id of your dropdown and use this code
var dom = document.getElementById("idofyourdropdown");
var result= dom. options [dom. selectedIndex]. text; //give selected text
I have a problem. I have a user control which contains multiple textboxes. When I update a value in one textbox it should calculate value and fill the value in another textbox automatically. I am writing Javascript code in Usercontrol.
When I change the value in the textbox, I am trying to get elementIDs of other textboxes.It shows me an error. It looks to me the elements are not present or they are somewhere else.
Can anyone give me a simple example?
Any help would be appreciated.
if you use jQuery...
var ids = [];
$('input[type=text]').each(function() {
ids.push($(this).attr('id'));
});
ids is now an array of all the ids of the inputs that have the type of text
Hello there i have written some code in jquery to add new input type elements in aspx page! Now I want to fetch values of these elements via ASP.NET! I know if i want to achieve this i will have to store each values in hidden form elements n then fetching hidden element val in cs file! I am curious if i could get a direct/shortcut way to fetch the values of each dynamically added contols in Asp.Net incase there were dozens of elements which were added dynamically in jquery!
Thanks in advance
When you add inputs on the client-side, the server doesn't have an object created to access its POST data like it does with your runat="server" controls. There are a few options:
1) Use a script to set the value of a runat="server" HiddenField before postback.
2) Access Request.Form["YourInputName"].
Give every element you add to your page a class, say "dynamic". Before postback, update a HiddenField like so:
var hiddenValues = "";
$(".dynamic").each(function(){
hiddenValues += $(this).val() + ",";
});
$("#hiddenField").val(hiddenValues);
Then access the comma delimited hidden field value in the code behind.