How to find tag in table structure using jQuery - jquery-selectors

I have the following html:
<table>
<tr>
<td>
<input type="button" id="btnAdd" value="Add" />
<input type="hidden" id="hdnID" value='209' class="hdn" />
</td>
</tr>
<tr>
<td>
<input type="button" id="btnAdd" value="Add" />
<input type="hidden" id="hdnID" value='210' class="hdn" />
</td>
</tr>
<tr>
<td>
<input type="button" id="btnAdd" value="Add" />
<input type="hidden" id="hdnID" value='211' class="hdn" />
</td>
</tr>
</table>
I have a jQuery click event for the add buttons.
$("#btnAdd").click(function ($e) {
// Need selector here that can find the hidden field (see above) that is found
// in the same td as the button that was clicked. For example, if the Add button
// in the 2nd row was clicked then I need to find the hidden input that has
// the value of '210'.
// Doesn't work... not sure why
var hdn = $(this).siblings().next();
});
Thanks in advance for helping me through a thick moment...

Maybe something like this would work?
("#btnAdd").click(function ($e) {
var hdn = $(this).parent().next().children('td input');
});

Related

Apache 2 html auto formatter?

Using perl 5.14 on Ubuntu 12.0.4 with Apache 2
In some way or another, when looking to the source in the webbrowser, my printed source is not matching. Some html formatter is executed, I want to turn it off.
Before I was using perl 5.6 with Apache and this issue did not occur.
Even is Html is not correctly formatted, it should not remove code in this way.
#!/usr/bin/perl
print "Content-type:text/html\n\n";
print<<EOF;
<table>
<tr><td><i>Search for</i></td><td><i>Search in ...</i></td><td></td></tr>
<tr><td valign="top">
<form action="$ENV{'SCRIPT_NAME'}" method="get">
<input type="text" class="formtext" id="txt2" autocomplete="off" name="find" size="53" maxlength="40" onkeyup="showResult2(this.value)" value="$QUERY{'find'}"><br><div id="livesearch2"></div>
<br>Option: <input type="checkbox" class="formtext" name="exact" $exactsel value="1"> Search Exact
</td><td valign="top">
<SELECT name="type" class="formtext"><OPTION $seltitle value="title">Titles<OPTION value="composer">Composers<OPTION value="track">Tracks<OPTION $selshop value="shop">Shopping</SELECT>
</td><td valign="top">
<INPUT type="hidden" name ="lang" value="en">
<INPUT type="submit" class="button" value="Search">
Here should be closing form tag, view source code, its has been removed? </form>
</td></tr></table>
EOF
Now the output in the web is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><body><table>
<tr><td><i>Search for</i></td><td><i>Search in ...</i></td><td></td></tr>
<tr><td valign="top">
<form action="/test.cgi" method="get">
<input type="text" class="formtext" id="txt2" autocomplete="off" name="find" size="53" maxlength="40" onkeyup="showResult2(this.value)" value="" /><br /><div id="livesearch2"></div>
<br />Option: <input type="checkbox" class="formtext" name="exact" value="1" /> Search Exact
</form></td><td valign="top">
<select name="type" class="formtext"><option value="title">Titles</option><option value="composer">Composers</option><option value="track">Tracks</option><option value="shop">Shopping</option></select>
</td><td valign="top">
<input type="hidden" name="lang" value="en" />
<input type="submit" class="button" value="Search" />
Here should be closing form tag, view source code, its has been removed?
</td></tr></table></body></html>
Html code is added and the </form> is gone and that is giving me issues. It is not browser related, all show the same. In the command line, the script print is correctly.
Is this an Apache2 setting or something else? Where/How can I change it?
Change it to look like this so the tags are properly nested:
<form action="$ENV{'SCRIPT_NAME'}" method="get">
<table>
<tr>
<td><i>Search for</i></td><td><i>Search in ...</i></td>
<td></td>
</tr>
<tr>
<td valign="top">
<input type="text" class="formtext" id="txt2" autocomplete="off" name="find" size="53" maxlength="40" onkeyup="showResult2(this.value)" value="$QUERY{'find'}"><br>
<div id="livesearch2"></div>
<br>Option: <input type="checkbox" class="formtext" name="exact" $exactsel value="1"> Search Exact
</td>
<td valign="top">
<SELECT name="type" class="formtext"><OPTION $seltitle value="title">Titles<OPTION value="composer">Composers<OPTION value="track">Tracks<OPTION $selshop value="shop">Shopping</SELECT>
</td>
<td valign="top">
<INPUT type="hidden" name ="lang" value="en">
<INPUT type="submit" class="button" value="Search">
</td>
</tr>
</table>
Here should be closing form tag, view source code, its has been removed?
</form>

Zend: How do i create custom form elements using setDecorators()?

I need the form html like below:
<form>
<div class="es_form_txt">Name</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="es_form_txt">Gender</div>
<div class="es_form">
<input type="radio" value="" name=""> Male
<input type="radio" value="" name=""> Female
<input type="radio" value="" name=""> Other
</div>
<div class="clear1"></div>
<div class="es_form_txt">Country Code</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="es_form_txt">Phone</div>
<div class="es_form"><input type="text" value="" class="email1"></div>
<div class="clear1"></div>
<div class="clear1"></div>
<div class="es_form"> </div>
<div class="es_form"><input type="button" class="button" value="Update"></div>
<div class="clear"></div>
</form>
I tried all sorts of solution in here not working! Could anyone point me in right direction?
I find that when I need to display specific HTML when using Zend_Form the most reliable solution is usually to use the ViewScript decorator.
Build a normal form using Zend_Form.
<?php
//application/forms/Search.php
class Application_Form_Search extends Zend_Form
{
public function init()
{
$this->setMethod('POST');
//assign the view script to the decorator, this can also be done in the controller
$this->setDecorators(array(
array('ViewScript', array(
'viewScript' => '_searchForm.phtml'
))
));
// create new element
$query = $this->createElement('text', 'query');
// element options
$query->setLabel('Search Keywords');
// add the element to the form
$this->addElement($query);
//submit element
$submit = $this->createElement('submit', 'search');
$submit->setLabel('Search Site');
$submit->setDecorators(array('ViewHelper'));
$this->addElement($submit);
}
}
Then build the actual script used to render the form.
<!-- ~/views/scripts/_searchForm.phtml -->
<article class="search">
<!-- set the action and the method -->
<form action="<?php echo $this->element->getAction()?>" method="<?php echo $this->element->getMethod()?>">
<table>
<tr>
<!-- you can render individual decorators. -->
<th><?php echo $this->element->query->renderLabel()?></th>
</tr>
<tr>
<td><?php echo $this->element->query->renderViewHelper()?></td>
</tr>
<tr>
<!-- or you can render a complete element -->
<td><?php echo $this->element->search?></td>
</tr>
</table>
</form>
</article>
This currently renders as:
<article class="search">
<form action="/video/index/display" method="post">
<table>
<tr>
<th>
<dt id="query-label">
<label for="query" class="optional">Search Keywords</label>
</dt>
</th>
</tr>
<tr>
<td>
<input type="text" name="query" id="query" value="" placeholder="Movie Title" size="20">
</td>
</tr>
<tr>
<td>
<input type="submit" name="search" id="search" value="Search Video Collection!">
</td>
</tr>
</table>
</form>
</article>
Some experimentation will be required to get exactly the output you require.

Form doesn't submit on Firefox

<table width=100% cellspacing=0 cellpadding=0 class="form_table">
<form name="suggestion_box" action="suggestion_box.php" method=post>
<input type="hidden" name="form_submit" value="1">
<tr>
<td width=40% align=right valign=top class="form_label_cell">
<b class="form_label">
First Name<br>
</b>
</td>
</table>
<br>
<input type="image" src="button_submit.gif" alt="Submit" class="input_gfx">
<input type="hidden" name="form_submit" value="1">
<br>
</form>
</table>
This is my form, I don't know why that doesn't work with Firefox, can you help me?
I've been reading hundreds of answers since weeks ago, but I couldn't make it work.
1) You can't place your form within the table like that.
2) You are closing your table (</table>) twice.
3) You never closed your row (</tr>).
Try this simplified code instead:
<form name="suggestion_box" action="suggestion_box.php" method=post>
<table width="100%" cellspacing="0" cellpadding="0" class="form_table">
<tr>
<td>
<input type="hidden" name="form_submit" value="1">
</td>
</tr>
<tr>
<td>
<b class="form_label">
First Name
</b>
</td>
</tr>
<tr>
<td>
<input type="submit" src="button_submit.gif" alt="Submit" class="input_gfx">
</td>
</tr>
</table>
</form>
You have to specify a name for your image input field.
<input type="image" name="yourimage" src="button_submit.gif" alt="Submit" class="input_gfx">
You can access the x/y values using the POST variables yourimage.x / yourimage.y (or in PHP yourimage_x, yourimage_y).
I have had problem with forms and inputs which don't have id's, Try giving id's to the form and form elements and add type="submit" to your submit button.

How to identify in table an input (check-box) followed by a text in <td>?

I have to identify the path of check boxes in a row from a table using the text preceding them. The problem is that the text is inserted in a 'td'.
The code is following:
<tr class="bz_row_even">
<td align="center">
<input type="checkbox"
name="email-0-10"
value="1"
checked>
</td>
<td align="center">
<input type="checkbox"
name="email-1-10"
value="1"
checked>
</td>
<td align="center">
<input type="checkbox"
name="email-2-10"
value="1"
checked>
</td>
<td align="center">
<input type="checkbox"
name="email-3-10"
value="1"
checked>
</td>
<td>A new bug is created
</td>
</tr></code></pre>
In this example I have 4 check-boxer for a row. My query should be with a count to check the check-boxes in turn.
Could somebody help me with the path of check-boxes?
Thank you in advance
If you don't use Se-IDE, this becomes much easier. Here I just add the path to a list, but could use get_attribute or similar on the element that is been used.
paths = []
for checkbox in range(se.get_css_count("css=#bz_row_even input"):
paths.append("css=#bz_row_even input[%d]" % checkbox)
Unless I completely misunderstand your question

custom signup "signupXhtml"

Greetings
I'm using the next object to customize the signupXhtml form
The code is the next
object User extends User with MetaMegaProtoUser[User] with ReCaptcha {
............................................
............................................
............................................
override def signupXhtml(user: User) = {
(<form method="post" action={ S.uri }>
<table>
<tr><td colspan="2">{ S.??("sign.up") }</td></tr>
{ localForm(user, false, signupFields) }
<tr><td> </td><td>{ captchaXhtml() }</td></tr>
<tr><td> </td><td><user:submit/></td></tr>
</table>
</form>)
}
............................................
............................................
............................................
}
and the output in html is the next
<form action="/my/signup" method="post">
<table>
<tr><td colspan="2">Sign Up</td></tr>
<tr>
<td>Username</td>
<td>
<input id="txtFirstName" name="F443739586660TOG" type="text" maxlength="32" value="" />
</td>
</tr>
<tr>
<td>Lastname</td>
<td>
<input id="txtLastName" name="F443739586661IYO" type="text" maxlength="32" value="" />
</td>
</tr>
<tr>
<td>email</td>
<td>
<input id="txtEmail" name="F443739586662Z43" type="text" maxlength="48" value="" />
</td>
</tr>
<tr>
<td>passwd</td>
<td>
<span>
<input value="*******" type="password" name="F443739586663IFM" /> Repeat
<input value="*******" type="password" name="F443739586663IFM" />
</span>
</td>
</tr>
...............................................
</table>
</form>
I need to customize the email field, as follows:
<input id="txtEmail" name="F443739586662Z43" type="text" maxlength="48" value="" onblur="return my_function();"/>
How insert onblur="return my_function();" on txtEmail element ?
I was reviewing:
http://scala-tools.org/mvnsites/liftweb-2.0/framework/lift-persistence/scaladocs/net/liftweb/mapper/ProtoUser.scala.html#Some%2896%29
and this:
http://www.devcomments.com/Example-custom-registration-at1131253.htm
but did not find anything to help me
anyone have any idea?
please!
I know that you can attach script commands to most of the built in ajax elements in lift by passing the script as an argument when you create an SHTML.text element. Lifts wiring is also something you might want to look into, I know that the Lift In Action has a chapter that goes into detail about attaching javascript to ajax elements and about wiring as well so that is something that you could look into. You could also post this to the mailing list or take a look through it, it will probably provide the best results
In your User class do something like:
override lazy val email = new CustomizedEmailField
protected class CustomizedEmailField(obj: User, size: Int) extends EmailField(obj, size) {
override def toForm: Box[NodeSeq] =
Full(SHtml.text("example#email.com", (s) => Alert("hello "+s), ("onblur", "callMyFunc();")))
}
This should override the default email field.