Dear Stackoverflow members,this question might seem very trivial and honestly I search for an answer however although there are similar queries around, none of the solutions delivered seem to work on what I am trying to achieve. I will put forth a generic snippet to understand what I am trying to achieve.
var dd = addday.getDate() + xdays; //addition of days to user input date
document.getElementById("Days").value= displaydate;//loading date to Days
where displaydate is in the following format:
var displaydate = dd+'/' + mm + '/' + y; //showing date format
and value shown in real time is displayed in the following input (disabled) box:
<label><b>Expiry Date:</b></label><input type="text" name="Days2" id ="Days2" disabled>
All the above is in a form. What I want to achieve thereafter is that when the user presses submit, that value attained and displayed by the getElementById is inserted in a table.
$addquery2="INSERT INTO 3pxdef_tb(defRef,tlpID,RaisedBy,RaisedDate,defDesc,defCAT,expDate,closedBy,closedDate,acID)VALUES('$_POST[def]','$_POST[tlptsel]','$_POST[raisedby]','$_POST[draised]','$_POST[des]','$_POST[catsel]','$_POST[Days]','$_POST[clby]','$_POST[closeddate]','$acindex')";
Unfortunately this is not working since an undefined index is being returned by the system.
Can I ask your assistance in this matter?
Thanking you so much.
There are two errors or I should say mistakes in your code first
Disabled input tags cannot be posted
see this for more information
Disabled form inputs do not appear in the request
Second
Just like what Luigi D'Amico said
You're Calling "Days" as id in your JS code but in your html code you have "Days2" as an ID and Name. Rename your Days2 into Days. Your php script also uses that one.
You say:
document.getElementById("Days").value
But the html tags id is "Days2"
<input type="text" name="Days2" id ="Days2"
Let us know if this was the issue or if it was just a typo
Related
So I am trying to find a way to extract data from the first row where the checkbox from the first column is unchecked. I know this may sound like a true beginner question but I couldn't manage to find how to do it despite searching for quite a few hours.
Here a step-by-step of my goal to clarify :
Find the first checkbox which is unchecked;
Retrieve information from another column (inner html) but from the corresponding row and an attribute ("name") of the checkbox;
Without opening it on-screen, use the attribute of the checkbox (partial URL) to open completed URL and retrieve more information into MySQL;
Check the checkbox;
Rince and repeat
I am only looking for info concerning step one and two, the rest is there for clarification. I do not have prior experience in Javascript writing prior my last few days of Internet browsing, the only coding I've done were statistical analysis in R.
Any help would be highly appreciated.
Thank you very much!
Nikola
Well, you can use the same class for every checkbox (i.e. rowcheck):
<input type="checkbox" class="rowcheck" id="CbRow_1" name="test" value="test">
And then you loop through the checkboxes:
$(".rowcheck").each(function (index, element) {
if ($(element).prop("checked")) {
//Get the row number from ID
var rownumber = $(element).prop("id").split("_")[1];
//Now you do stuff with the other element
$("#element_" + rownumber).html("whatever")
}
});
First, please forgive me, as I know very little about JavaScript, and am trying to make something work without knowing proper terms and syntax. I am working within the CMS called "ViArt." A lot of what is going on is handled by php, and I only have access in ViArt to add JavaScript to an onChange event for a listbox.
Here is what I'm trying to accomplish:
The product is sunglasses. Different frame colors in a listbox 1 are designated by a numerical prefix. There are 30 different lens color options for each frame color, and these lens colors are chosen in listbox 2.
Using my current code, for each frame, I have to go in the JavaScript for each frame and manually enter the numerical prefix designated to that frame.
This is my current, working code in an onChange event:
=================================
var FrameNo = '01';//ENTER FRAME NUMBER
var ImagePath = 'images/GlassesBrand/Rx/GlassesTest/';//ENTER PATH TO IMAGES
var ImageNamePrefix = 'GlassesTest-XL';//ENTER NAMING CONVENTION
// This changes the IMAGE hyperlink to larger image to match user's selection
document.getElementById('blackImg').href=ImagePath + 'Large/' + ImageNamePrefix + '-Frame' + FrameNo + '-Lens' +
this.form.property{form_id}_{property_id}.options[this.form.property{form_id}_{property_id}.selectedIndex].text.substrin g(0,2) + '.jpg';
=================================
The change I want to make, is that I don't want to have to hard-code "FrameNo." I want to call that dynamically within the onChange event, by looking up the selectedIndex of listbox 1.
=============================
In an onChange event for list box 2, named "{property_id}," I am trying to get the selectedIndex of a listbox 1, named "{property_parent_id6385_6773}"
{form_id} value is 6385
{property_id} is listbox 2, and in this example, the value is 6773
{property_parent_id6385_6773} value is 6765, and in this example, this refers to listbox 1
{property_parent_id6385_6773} is named dynamically by a php script or something. For example, on the next form, it may be called {property_parent_id6400_6800}. So I am trying to program the JavaScript to dynamically refer to the property_parent_id####_####, based on whatever form and list box I'm working with.
When I hard-code or semi-hard code it for testing, the following methods work:
this.form.property6385_6765.selectedIndex;
and
this.form.property{form_id}_6765.selectedIndex;
I don't know the syntax, so I thought declaring some things in variables might help me get what I needed.
From my notes:
var FrameBox = [this.form.property_parent_id6385_6773.value]; //WHICH EQUALS "6765"
var FrameNo = 'this.form.property' + {form_id} + '_' + FrameBox + '.selectedIndex';
RESULTS IN:
http://www.companyname.com/images/GlassesBrand/Rx/GlassesTest/Large/GlassesBrand-GlassesTest-XL-Framethis.form.property6385_6765.selectedIndex-Lens02.jpg
Whereas, an example of the result I am seeking is:
http://www.companyname.com/images/GlassesBrand/Rx/GlassesTest/Large/GlassesBrand-GlassesTest-XL-Frame1-Lens02.jpg
==============================
In summary, I know what I need, but I don't understand enough of the syntax.
I know this could be better phrased, but this is all new to me. On the bright side, I am now inspired to take a class in JavaScript.
Any help would be greatly appreciated.
This is more of a calculated guess but could be worth a try.
this.form.property_parent_id{form_id}_{property_id}.options[this.form.property_parent_id{form_id}_{property_id}.selectedIndex].text
I am very new to JavaScript and would like to know how to go about the following.
I have a form that I am using for entry to a fishing contest.
It contains fields for up to six anglers but they only fill out two.
What I am attempting to do is where a contest is declared via the form I add a value (the entry fee) to a hidden field on the form.
Like:
if form.anglername1 <> "" then form.angler1fee = "75"
Have tried various methods I have seen on the web without success.
Having said that I really don't know what I am doing.
Have been a Clarion coder for too many years to talk about and am finding JavaScript just a little tough.
If anyone can help a little I would be very happy.
Without seeing more code, I'm not sure exactly how to do what you want, but the snippet you gave isn't JavaScript. Here is the proper JS syntax for what you have written.
if(form.anglename1 != ""){
form.anglerfee = "75";
}
why to add an hidden field? try this with your input field:
<input name="anglername1" onblur="this.value=this.value==''?'75':this.value;"
onfocus="this.value = this.value == this.defaultValue? '' : this.value;" />
HTH !
Hi I have a datatables based table that holds data. I need to be able to get the values out of the following string that I have been able to do so far.
<input name="jobNo" value="job_no_123" />job_no_123
I need to be able to get the name and the value and store into separate variables that I then pass off to do something else.
However I do also have another 4 fields on the page that I need to capture too:
<input name="item_1" value="data1" />data1
<input name="item_2" value="data2" />data2
<input name="item_3" value="data3" />data3
<input name="item_4" value="data4" />data4
And of top of this, this would only be the data from one row, and I need to do this for multiple rows too. But I need to start somewhere.
Please help.
Thanks
I am not sure what are your needs but here is a code that should help
$('input').each(function(i, val){
$(this).attr('name'); // will get the attribute name
$(this).attr('value'); // will get the attribute value
$(this).attr('text'); // will get the text inside the input
});
This regex can find the values from your code. However, it assumes that the input is strictly in that format, with no variations in even whitespace.
<input name="(.*)" value="(.*)" />
The values will be in captured groups 1 and 2.
Note: I am aware that regex should not be used to parse HTML, but if the input is strict enough, it works.
I am a predominantly PHP developer. I realize in this day and age specialization in one scripting language doesn't cut it, but the fact remains that my skills at JavaScript and jQuery are pretty green. I am a novice at best. I can create my own code but Cross Browser compatibility remains a huge issue with my work in JavaScript.
Anyway, I have a script that filters products according to categories/subcategories. This is how it works: you select a category and the javascript in the background does its thing to filter the subcategories so that the options displayed are the ones pertaining to the parent category- a combination of these two filters the product line.
Here is my code:
function scategories(){
//get the category option value from the category drop down bar
var cat = (document.getElementById('categories').value);
//get all the options from the subcategory drop down bar
var subcat = document.getElementsByClassName('subcategories');
var n=0;
//if the category bar option is set to 0 display everything
if(Number(cat)==0){
Show();
}
//filter the subcategories
while(subcat.item(n)){
//if there is no match b/w the subcategories option and the categories id FILTER
if(Number((subcat.item(n).value).split('|')[1]) != Number(cat) && Number(subcat.item(n).value) != 0){
document.getElementsByClassName('subcategories')
.item(n)
.style
.display="none";
}else{
//else display the subcategory
document.getElementsByClassName('subcategories')
.item(n)
.style
.display="list-item";
}
n++;
}
}
This code is pretty self explanatory I would say. I also have a shiftfocus function that shifts the focus from the current option selected in the subcategory to the default one which is 'none' whenever a new category is picked. This basically resets the subcategory.. here's the code:
function shiftfocus(){
document.getElementsByClassName('subcategories')
.item(0)
.removeAttribute("selected");
document.getElementsByClassName('subcategories')
.item(0)
.setAttribute("selected","selected");
}
Shiftfocus is called onChange and scategories is called onClick.
Problem 1:
1) Firefox: Shiftfocus doesn't shift the focus to the default option even though I can see it adds the 'selected' attribute.
2) Safari: Does not work at all.
EDIT: Problem 2 was the product of a careless mistake. I left open an anchor tag which was
creating havoc in IE. Should have double checked before bothering you
guys. Sorry. Problem 1 still persists.
Problem 2:
I understand none of us developers particularly like internet explorer. But I am willing to believe I have made a mistake here. I have some jQuery that fetches data from a script in another file via the native POST function and appends it to a table with the id "content". This works fine on every browser, except IE. If I try going back to IE 7,8 compatibility mode the results are a little better (the data shows up broken in pieces though) and in IE9 compatibility mode nothing is appended at all! Here's the code:
$.post("bagcontents.php", {
"Bid": $(this).attr('bid')
},
function(data){
$("#content").empty().append(data);
roundNumber();
$('#processorder_hidden').attr('value',currentBid);
});
//append here
<div id="contents" style="overflow:auto;height:345px;padding-right:5px;">
<form name="bag_contents" id="bag_contents" method="post" action="<?php _page ;?>">
<table id="content">
</table>
<input type="hidden" id="bag_contents_hidden" name="bag_contents_hidden" value="1" />
</form>
</div>
Any help will be appreciated. I tried outputting the fetched results with alert, alert(data), and the script is fetching everything just fine. Its the just the append part that fails :|
Here are some suggestions and hope you find them somewhat useful.
Problem: 1
Instead of having the shiftfocus() set the to a specific value, have you tried using .val('') just to clear it out. I can imagine that this will default to the first option.
Problem: 2
This will be hard to debug without knowing what data is coming back from the server. Might be bad formatting or some syntax error on the rendered output.